package com.lzy.pattern.singleton.demo2;

/**
 * @ClassName: Singleton
 * @Description: 单例设计模式：饿汉式，静态代码块中创建该类对象
 * @Author: LiuZy
 * @Date: 2022/4/9 19:23
 * @Version: 1.0
 */
public class Singleton {
    //1.私有化无参构造方法
    private Singleton(){}

    //2.创建静态成员变量
    private static Singleton instance;

    static {
        instance = new Singleton();
    }

    //3.对外提供静态方法获取该类对象
    public static Singleton getInstance(){
        return instance;
    }
}